package com.kexio.user.dto;

import java.io.Serializable;

/**
 * 菜单统计信息DTO
 * 
 * 用于传输菜单相关的统计数据，包括：
 * - 菜单总数和状态分布
 * - 菜单类型分布
 * - 菜单可见性分布
 * - 菜单层级分布
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
public class MenuStatistics implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    // ==================== 基础统计 ====================
    
    /**
     * 菜单总数
     */
    private Integer totalMenus = 0;
    
    /**
     * 启用状态的菜单数量
     */
    private Integer enabledMenus = 0;
    
    /**
     * 禁用状态的菜单数量
     */
    private Integer disabledMenus = 0;
    
    // ==================== 可见性统计 ====================
    
    /**
     * 可见的菜单数量
     */
    private Integer visibleMenus = 0;
    
    /**
     * 隐藏的菜单数量
     */
    private Integer hiddenMenus = 0;
    
    // ==================== 类型统计 ====================
    
    /**
     * 目录菜单数量（M类型）
     */
    private Integer directoryMenus = 0;
    
    /**
     * 页面菜单数量（C类型）
     */
    private Integer pageMenus = 0;
    
    /**
     * 按钮菜单数量（F类型）
     */
    private Integer buttonMenus = 0;
    
    // ==================== 层级统计 ====================
    
    /**
     * 根菜单数量（没有父菜单的菜单）
     */
    private Integer rootMenus = 0;
    
    /**
     * 子菜单数量（有父菜单的菜单）
     */
    private Integer childMenus = 0;
    
    /**
     * 最大菜单层级深度
     */
    private Integer maxDepth = 0;
    
    /**
     * 平均菜单层级深度
     */
    private Double avgDepth = 0.0;
    
    // ==================== 外链统计 ====================
    
    /**
     * 外链菜单数量
     */
    private Integer externalMenus = 0;
    
    /**
     * 内部菜单数量
     */
    private Integer internalMenus = 0;
    
    // ==================== 缓存统计 ====================
    
    /**
     * 需要缓存的菜单数量
     */
    private Integer cachedMenus = 0;
    
    /**
     * 不缓存的菜单数量
     */
    private Integer uncachedMenus = 0;
    
    // ==================== 权限统计 ====================
    
    /**
     * 有权限标识的菜单数量
     */
    private Integer menusWithPermission = 0;
    
    /**
     * 无权限标识的菜单数量
     */
    private Integer menusWithoutPermission = 0;
    
    /**
     * 关联的权限总数
     */
    private Integer relatedPermissions = 0;
    
    // ==================== 构造函数 ====================
    
    public MenuStatistics() {
    }
    
    // ==================== Getter/Setter ====================
    
    public Integer getTotalMenus() {
        return totalMenus;
    }
    
    public void setTotalMenus(Integer totalMenus) {
        this.totalMenus = totalMenus;
    }
    
    public Integer getEnabledMenus() {
        return enabledMenus;
    }
    
    public void setEnabledMenus(Integer enabledMenus) {
        this.enabledMenus = enabledMenus;
    }
    
    public Integer getDisabledMenus() {
        return disabledMenus;
    }
    
    public void setDisabledMenus(Integer disabledMenus) {
        this.disabledMenus = disabledMenus;
    }
    
    public Integer getVisibleMenus() {
        return visibleMenus;
    }
    
    public void setVisibleMenus(Integer visibleMenus) {
        this.visibleMenus = visibleMenus;
    }
    
    public Integer getHiddenMenus() {
        return hiddenMenus;
    }
    
    public void setHiddenMenus(Integer hiddenMenus) {
        this.hiddenMenus = hiddenMenus;
    }
    
    public Integer getDirectoryMenus() {
        return directoryMenus;
    }
    
    public void setDirectoryMenus(Integer directoryMenus) {
        this.directoryMenus = directoryMenus;
    }
    
    public Integer getPageMenus() {
        return pageMenus;
    }
    
    public void setPageMenus(Integer pageMenus) {
        this.pageMenus = pageMenus;
    }
    
    public Integer getButtonMenus() {
        return buttonMenus;
    }
    
    public void setButtonMenus(Integer buttonMenus) {
        this.buttonMenus = buttonMenus;
    }
    
    public Integer getRootMenus() {
        return rootMenus;
    }
    
    public void setRootMenus(Integer rootMenus) {
        this.rootMenus = rootMenus;
    }
    
    public Integer getChildMenus() {
        return childMenus;
    }
    
    public void setChildMenus(Integer childMenus) {
        this.childMenus = childMenus;
    }
    
    public Integer getMaxDepth() {
        return maxDepth;
    }
    
    public void setMaxDepth(Integer maxDepth) {
        this.maxDepth = maxDepth;
    }
    
    public Double getAvgDepth() {
        return avgDepth;
    }
    
    public void setAvgDepth(Double avgDepth) {
        this.avgDepth = avgDepth;
    }
    
    public Integer getExternalMenus() {
        return externalMenus;
    }
    
    public void setExternalMenus(Integer externalMenus) {
        this.externalMenus = externalMenus;
    }
    
    public Integer getInternalMenus() {
        return internalMenus;
    }
    
    public void setInternalMenus(Integer internalMenus) {
        this.internalMenus = internalMenus;
    }
    
    public Integer getCachedMenus() {
        return cachedMenus;
    }
    
    public void setCachedMenus(Integer cachedMenus) {
        this.cachedMenus = cachedMenus;
    }
    
    public Integer getUncachedMenus() {
        return uncachedMenus;
    }
    
    public void setUncachedMenus(Integer uncachedMenus) {
        this.uncachedMenus = uncachedMenus;
    }
    
    public Integer getMenusWithPermission() {
        return menusWithPermission;
    }
    
    public void setMenusWithPermission(Integer menusWithPermission) {
        this.menusWithPermission = menusWithPermission;
    }
    
    public Integer getMenusWithoutPermission() {
        return menusWithoutPermission;
    }
    
    public void setMenusWithoutPermission(Integer menusWithoutPermission) {
        this.menusWithoutPermission = menusWithoutPermission;
    }
    
    public Integer getRelatedPermissions() {
        return relatedPermissions;
    }
    
    public void setRelatedPermissions(Integer relatedPermissions) {
        this.relatedPermissions = relatedPermissions;
    }
    
    // ==================== 便捷方法 ====================
    
    /**
     * 计算启用菜单的百分比
     * 
     * @return 启用菜单百分比（0-100）
     */
    public double getEnabledPercentage() {
        if (totalMenus == null || totalMenus == 0) {
            return 0.0;
        }
        return (enabledMenus * 100.0) / totalMenus;
    }
    
    /**
     * 计算禁用菜单的百分比
     * 
     * @return 禁用菜单百分比（0-100）
     */
    public double getDisabledPercentage() {
        if (totalMenus == null || totalMenus == 0) {
            return 0.0;
        }
        return (disabledMenus * 100.0) / totalMenus;
    }
    
    /**
     * 计算可见菜单的百分比
     * 
     * @return 可见菜单百分比（0-100）
     */
    public double getVisiblePercentage() {
        if (totalMenus == null || totalMenus == 0) {
            return 0.0;
        }
        return (visibleMenus * 100.0) / totalMenus;
    }
    
    /**
     * 计算隐藏菜单的百分比
     * 
     * @return 隐藏菜单百分比（0-100）
     */
    public double getHiddenPercentage() {
        if (totalMenus == null || totalMenus == 0) {
            return 0.0;
        }
        return (hiddenMenus * 100.0) / totalMenus;
    }
    
    /**
     * 计算目录菜单的百分比
     * 
     * @return 目录菜单百分比（0-100）
     */
    public double getDirectoryPercentage() {
        if (totalMenus == null || totalMenus == 0) {
            return 0.0;
        }
        return (directoryMenus * 100.0) / totalMenus;
    }
    
    /**
     * 计算页面菜单的百分比
     * 
     * @return 页面菜单百分比（0-100）
     */
    public double getPagePercentage() {
        if (totalMenus == null || totalMenus == 0) {
            return 0.0;
        }
        return (pageMenus * 100.0) / totalMenus;
    }
    
    /**
     * 计算按钮菜单的百分比
     * 
     * @return 按钮菜单百分比（0-100）
     */
    public double getButtonPercentage() {
        if (totalMenus == null || totalMenus == 0) {
            return 0.0;
        }
        return (buttonMenus * 100.0) / totalMenus;
    }
    
    /**
     * 验证统计数据的一致性
     * 
     * @return true-数据一致，false-数据不一致
     */
    public boolean isDataConsistent() {
        // 检查状态统计一致性
        if (enabledMenus + disabledMenus != totalMenus) {
            return false;
        }
        
        // 检查可见性统计一致性
        if (visibleMenus + hiddenMenus != totalMenus) {
            return false;
        }
        
        // 检查类型统计一致性
        if (directoryMenus + pageMenus + buttonMenus > totalMenus) {
            return false;
        }
        
        // 检查层级统计一致性
        if (rootMenus + childMenus != totalMenus) {
            return false;
        }
        
        // 检查外链统计一致性
        if (externalMenus + internalMenus != totalMenus) {
            return false;
        }
        
        // 检查缓存统计一致性
        if (cachedMenus + uncachedMenus != totalMenus) {
            return false;
        }
        
        // 检查权限统计一致性
        if (menusWithPermission + menusWithoutPermission != totalMenus) {
            return false;
        }
        
        return true;
    }
    
    /**
     * 重新计算衍生统计数据
     */
    public void recalculate() {
        if (totalMenus != null && enabledMenus != null) {
            this.disabledMenus = totalMenus - enabledMenus;
        }
        
        if (totalMenus != null && visibleMenus != null) {
            this.hiddenMenus = totalMenus - visibleMenus;
        }
        
        if (totalMenus != null && rootMenus != null) {
            this.childMenus = totalMenus - rootMenus;
        }
        
        if (totalMenus != null && externalMenus != null) {
            this.internalMenus = totalMenus - externalMenus;
        }
        
        if (totalMenus != null && cachedMenus != null) {
            this.uncachedMenus = totalMenus - cachedMenus;
        }
        
        if (totalMenus != null && menusWithPermission != null) {
            this.menusWithoutPermission = totalMenus - menusWithPermission;
        }
    }
    
    @Override
    public String toString() {
        return "MenuStatistics{" +
                "totalMenus=" + totalMenus +
                ", enabledMenus=" + enabledMenus +
                ", disabledMenus=" + disabledMenus +
                ", visibleMenus=" + visibleMenus +
                ", hiddenMenus=" + hiddenMenus +
                ", directoryMenus=" + directoryMenus +
                ", pageMenus=" + pageMenus +
                ", buttonMenus=" + buttonMenus +
                ", rootMenus=" + rootMenus +
                ", childMenus=" + childMenus +
                ", maxDepth=" + maxDepth +
                ", avgDepth=" + avgDepth +
                '}';
    }
}
